using System;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace time
{
    public class stopwatch1
    {
        public static void t2()
        {
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            Thread.Sleep(10000);
            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                ts.Hours, ts.Minutes, ts.Seconds,
                ts.Milliseconds / 10);
            Console.WriteLine("RunTime " + elapsedTime);
        }

        public static void Main1()
        {
            string s = "";

            try
            {
                aa();
            }
            catch (Exception ex)
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                //Stopwatch
                StackTrace trace = new StackTrace(ex, true);
                //StackFrame frame = trace.GetFrame(0);
                foreach (StackFrame item in trace.GetFrames())
                {
                    //s += item.GetFileName() + " " + item.GetMethod() + " " + item.GetFileLineNumber() + "\n";
                    s += Path.GetFileName(item.GetFileName()) + " " + item.GetMethod() + " " + item.GetFileLineNumber() + "\n";
                }

                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
               ts.Hours, ts.Minutes, ts.Seconds,
               ts.Milliseconds);
                Console.WriteLine("RunTime " + elapsedTime);
            }
            finally
            {
                Console.Write(s);
            }
        }

        private static void aa()
        {
            bb();
        }

        private static void bb()
        {
            int j = 0;
            int i = 100 / j;
        }
    }
}